{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2022春 《交互式数据可视化》 week06\n",
    "\n",
    "主讲 许智超\n",
    "\n",
    "时间：2022.04.06"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "## 1. 时间序列（Time series）\n",
    "* 处理时间数据：\n",
    "\n",
    "```\n",
    "import numpy as np\n",
    "\n",
    "aapl_dates=np.array(AAPL[\"date\"],dtype=np.datetime64)\n",
    "aapl_dates\n",
    "```\n",
    "## 2. 画布准备之：TOOLTIPS（交互式数据显示）\n",
    "\n",
    "```\n",
    "TOOLTIPS = [\n",
    "    (\"close\", \"@appl_close_data\"),\n",
    "    (\"high\", \"@appl_high_data\")\n",
    "]\n",
    "```\n",
    "\n",
    "\n",
    "## 3. 图形其他设置（交互式数据显示）\n",
    "\n",
    "```\n",
    "plot.legend.location='top_left'\n",
    "plot.legend.click_policy = 'hide'\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1002\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  const force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  const JS_MIME_TYPE = 'application/javascript';\n",
       "  const HTML_MIME_TYPE = 'text/html';\n",
       "  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  const CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    const script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    const cell = handle.cell;\n",
       "\n",
       "    const id = cell.output_area._bokeh_element_id;\n",
       "    const server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd_clean, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            const id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd_destroy);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    const output_area = handle.output_area;\n",
       "    const output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      const bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      const script_attrs = bk_div.children[0].attributes;\n",
       "      for (let i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      const toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    const events = require('base/js/events');\n",
       "    const OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  const NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    const el = document.getElementById(\"1002\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error(url) {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < css_urls.length; i++) {\n",
       "      const url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < js_urls.length; i++) {\n",
       "      const url = js_urls[i];\n",
       "      const element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n",
       "  const css_urls = [];\n",
       "  \n",
       "\n",
       "  const inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (let i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    const el = document.getElementById(\"1002\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n  const css_urls = [];\n  \n\n  const inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周知识：柱状图\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基本柱状图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 垂直柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"fa5712f3-3133-4563-88fe-5a5af17a448f\" data-root-id=\"1003\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"d27b2b7e-09f3-4b95-8e1f-b37ce360b28c\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1012\"}],\"center\":[{\"id\":\"1015\"},{\"id\":\"1019\"}],\"height\":400,\"left\":[{\"id\":\"1016\"}],\"renderers\":[{\"id\":\"1038\"}],\"title\":{\"id\":\"1040\"},\"toolbar\":{\"id\":\"1027\"},\"width\":400,\"x_range\":{\"id\":\"1004\"},\"x_scale\":{\"id\":\"1008\"},\"y_range\":{\"id\":\"1006\"},\"y_scale\":{\"id\":\"1010\"}},\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"overlay\":{\"id\":\"1026\"}},\"id\":\"1022\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1049\"},\"selection_policy\":{\"id\":\"1048\"}},\"id\":\"1034\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1025\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"red\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1037\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1004\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"AllLabels\"},{\"attributes\":{\"tools\":[{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"},{\"id\":\"1025\"}]},\"id\":\"1027\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1006\",\"type\":\"DataRange1d\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1026\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1008\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1010\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1046\"},\"group\":null,\"major_label_policy\":{\"id\":\"1047\"},\"ticker\":{\"id\":\"1013\"}},\"id\":\"1012\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1043\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1013\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"hatch_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1035\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1012\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1015\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1043\"},\"group\":null,\"major_label_policy\":{\"id\":\"1044\"},\"ticker\":{\"id\":\"1017\"}},\"id\":\"1016\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"1034\"}},\"id\":\"1039\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1017\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1036\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1016\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1019\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1046\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1047\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1040\",\"type\":\"Title\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1034\"},\"glyph\":{\"id\":\"1035\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1037\"},\"nonselection_glyph\":{\"id\":\"1036\"},\"view\":{\"id\":\"1039\"}},\"id\":\"1038\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1048\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1049\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1021\",\"type\":\"WheelZoomTool\"}],\"root_ids\":[\"1003\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"d27b2b7e-09f3-4b95-8e1f-b37ce360b28c\",\"root_ids\":[\"1003\"],\"roots\":{\"1003\":\"fa5712f3-3133-4563-88fe-5a5af17a448f\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1003"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400, plot_height=400)\n",
    "p.vbar(x=[1, 2, 3], width=0.5, bottom=0,\n",
    "       top=[1.2, 2.5, 3.7], color=\"red\")  # 垂直柱状图\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 水平柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"3206f1e8-6ec4-4bcd-83ff-27382c4c3f18\" data-root-id=\"1139\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"da027981-e323-49e6-a303-22af14fdb07c\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1148\"}],\"center\":[{\"id\":\"1151\"},{\"id\":\"1155\"}],\"height\":400,\"left\":[{\"id\":\"1152\"}],\"renderers\":[{\"id\":\"1174\"}],\"title\":{\"id\":\"1187\"},\"toolbar\":{\"id\":\"1163\"},\"width\":400,\"x_range\":{\"id\":\"1140\"},\"x_scale\":{\"id\":\"1144\"},\"y_range\":{\"id\":\"1142\"},\"y_scale\":{\"id\":\"1146\"}},\"id\":\"1139\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1194\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1159\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1195\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1160\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"right\":[1.2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1196\"},\"selection_policy\":{\"id\":\"1195\"}},\"id\":\"1170\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1196\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1161\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"navy\"},\"hatch_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1171\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"1140\",\"type\":\"DataRange1d\"},{\"attributes\":{\"tools\":[{\"id\":\"1156\"},{\"id\":\"1157\"},{\"id\":\"1158\"},{\"id\":\"1159\"},{\"id\":\"1160\"},{\"id\":\"1161\"}]},\"id\":\"1163\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1142\",\"type\":\"DataRange1d\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1162\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1144\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"navy\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1173\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"1146\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"navy\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1172\",\"type\":\"HBar\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1193\"},\"group\":null,\"major_label_policy\":{\"id\":\"1194\"},\"ticker\":{\"id\":\"1149\"}},\"id\":\"1148\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1149\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1148\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1151\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1190\"},\"group\":null,\"major_label_policy\":{\"id\":\"1191\"},\"ticker\":{\"id\":\"1153\"}},\"id\":\"1152\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1170\"}},\"id\":\"1175\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1152\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1155\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1170\"},\"glyph\":{\"id\":\"1171\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1173\"},\"nonselection_glyph\":{\"id\":\"1172\"},\"view\":{\"id\":\"1175\"}},\"id\":\"1174\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1187\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1190\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1156\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1191\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1157\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1193\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"1162\"}},\"id\":\"1158\",\"type\":\"BoxZoomTool\"}],\"root_ids\":[\"1139\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"da027981-e323-49e6-a303-22af14fdb07c\",\"root_ids\":[\"1139\"],\"roots\":{\"1139\":\"3206f1e8-6ec4-4bcd-83ff-27382c4c3f18\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1139"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400, plot_height=400)\n",
    "p.hbar(y=[1, 2, 3], height=0.5, left=0,\n",
    "       right=[1.2, 2.5, 3.7], color=\"navy\")  # 水平柱状图\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 案例DEMO（1）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"bb94f901-a847-496b-892e-9e0aa345559a\" data-root-id=\"1793\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"7abd7cbb-bbc2-4a3e-b167-86b32e497d5f\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1804\"}],\"center\":[{\"id\":\"1806\"},{\"id\":\"1810\"}],\"height\":350,\"left\":[{\"id\":\"1807\"}],\"renderers\":[{\"id\":\"1829\"}],\"title\":{\"id\":\"1794\"},\"toolbar\":{\"id\":\"1818\"},\"x_range\":{\"id\":\"1796\"},\"x_scale\":{\"id\":\"1800\"},\"y_range\":{\"id\":\"1798\"},\"y_scale\":{\"id\":\"1802\"}},\"id\":\"1793\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1805\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1828\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1804\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1806\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1800\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1895\"},\"group\":null,\"major_label_policy\":{\"id\":\"1896\"},\"ticker\":{\"id\":\"1808\"}},\"id\":\"1807\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1826\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1802\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1808\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1825\"}},\"id\":\"1830\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1807\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1810\",\"type\":\"Grid\"},{\"attributes\":{\"start\":0},\"id\":\"1798\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1827\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1825\"},\"glyph\":{\"id\":\"1826\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1828\"},\"nonselection_glyph\":{\"id\":\"1827\"},\"view\":{\"id\":\"1830\"}},\"id\":\"1829\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts\"},\"id\":\"1794\",\"type\":\"Title\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1898\"},\"group\":null,\"major_label_policy\":{\"id\":\"1899\"},\"ticker\":{\"id\":\"1805\"}},\"id\":\"1804\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"data\":{\"top\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1901\"},\"selection_policy\":{\"id\":\"1900\"}},\"id\":\"1825\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1900\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1796\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1811\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1812\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1817\"}},\"id\":\"1813\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1898\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1814\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1895\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1815\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1899\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1816\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1896\",\"type\":\"AllLabels\"},{\"attributes\":{\"tools\":[{\"id\":\"1811\"},{\"id\":\"1812\"},{\"id\":\"1813\"},{\"id\":\"1814\"},{\"id\":\"1815\"},{\"id\":\"1816\"}]},\"id\":\"1818\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1817\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1901\",\"type\":\"Selection\"}],\"root_ids\":[\"1793\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"7abd7cbb-bbc2-4a3e-b167-86b32e497d5f\",\"root_ids\":[\"1793\"],\"roots\":{\"1793\":\"bb94f901-a847-496b-892e-9e0aa345559a\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1793"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "# 画布\n",
    "p = figure(x_range=fruits, plot_height=350, title=\"Fruit Counts\",\n",
    "#            toolbar_location=None,\n",
    "#            tools=\"\"\n",
    "         )\n",
    "# 柱状图\n",
    "p.vbar(x=fruits, top=counts, width=0.9)\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 案例DEMO（2）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"c1df7dc9-4655-4a38-b257-2ba2cff0cbce\" data-root-id=\"1953\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"0116f6fd-72df-48ed-a02e-f4b4001e4b25\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1964\"}],\"center\":[{\"id\":\"1966\"},{\"id\":\"1970\"}],\"height\":350,\"left\":[{\"id\":\"1967\"}],\"renderers\":[{\"id\":\"1989\"}],\"title\":{\"id\":\"1954\"},\"toolbar\":{\"id\":\"1978\"},\"x_range\":{\"id\":\"1956\"},\"x_scale\":{\"id\":\"1960\"},\"y_range\":{\"id\":\"1958\"},\"y_scale\":{\"id\":\"1962\"}},\"id\":\"1953\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1975\",\"type\":\"ResetTool\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1985\"},\"glyph\":{\"id\":\"1986\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1988\"},\"nonselection_glyph\":{\"id\":\"1987\"},\"view\":{\"id\":\"1990\"}},\"id\":\"1989\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"factors\":[\"Plums\",\"Pears\",\"Nectarines\",\"Grapes\",\"Apples\",\"Strawberries\"]},\"id\":\"1956\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1976\",\"type\":\"HelpTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts\"},\"id\":\"1954\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2071\",\"type\":\"Selection\"},{\"attributes\":{\"tools\":[{\"id\":\"1971\"},{\"id\":\"1972\"},{\"id\":\"1973\"},{\"id\":\"1974\"},{\"id\":\"1975\"},{\"id\":\"1976\"}]},\"id\":\"1978\",\"type\":\"Toolbar\"},{\"attributes\":{\"start\":0},\"id\":\"1958\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2070\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1977\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1960\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1962\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1988\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2068\"},\"group\":null,\"major_label_policy\":{\"id\":\"2069\"},\"ticker\":{\"id\":\"1965\"}},\"id\":\"1964\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2065\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"1977\"}},\"id\":\"1973\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1965\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1964\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1966\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2069\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2065\"},\"group\":null,\"major_label_policy\":{\"id\":\"2066\"},\"ticker\":{\"id\":\"1968\"}},\"id\":\"1967\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1986\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1968\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1985\"}},\"id\":\"1990\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1967\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1970\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1987\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1971\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2066\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1972\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2068\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"data\":{\"top\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"2071\"},\"selection_policy\":{\"id\":\"2070\"}},\"id\":\"1985\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1974\",\"type\":\"SaveTool\"}],\"root_ids\":[\"1953\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"0116f6fd-72df-48ed-a02e-f4b4001e4b25\",\"root_ids\":[\"1953\"],\"roots\":{\"1953\":\"c1df7dc9-4655-4a38-b257-2ba2cff0cbce\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1953"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "# 排序\n",
    "sorted_fruits = sorted(fruits, key=lambda x: counts[fruits.index(x)])\n",
    "# 画布\n",
    "p = figure(x_range=sorted_fruits, plot_height=350, title=\"Fruit Counts\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图\n",
    "p.vbar(x=fruits, top=counts, width=0.9)\n",
    "# 其他\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践（1）2019年7月常见可视化工具Github标星数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"e3f577a8-d62e-4798-8eeb-b39164d87341\" data-root-id=\"1373\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"dddafc83-2e0c-4b39-b254-6676fec097da\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1384\"}],\"center\":[{\"id\":\"1386\"},{\"id\":\"1390\"}],\"left\":[{\"id\":\"1387\"}],\"renderers\":[{\"id\":\"1409\"}],\"title\":{\"id\":\"1374\"},\"toolbar\":{\"id\":\"1398\"},\"x_range\":{\"id\":\"1376\"},\"x_scale\":{\"id\":\"1380\"},\"y_range\":{\"id\":\"1378\"},\"y_scale\":{\"id\":\"1382\"}},\"id\":\"1373\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"fill_color\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1408\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1385\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1446\",\"type\":\"AllLabels\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1376\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1448\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1445\"},\"group\":null,\"major_label_policy\":{\"id\":\"1446\"},\"ticker\":{\"id\":\"1388\"}},\"id\":\"1387\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1406\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1449\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1388\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1450\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1374\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"1387\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1390\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1451\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"1384\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1386\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1405\"}},\"id\":\"1410\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1405\"},\"glyph\":{\"id\":\"1406\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1408\"},\"nonselection_glyph\":{\"id\":\"1407\"},\"view\":{\"id\":\"1410\"}},\"id\":\"1409\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1380\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"hatch_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[9678,11034,5387,6038,4928,3783],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1451\"},\"selection_policy\":{\"id\":\"1450\"}},\"id\":\"1405\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1382\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1391\",\"type\":\"PanTool\"},{\"attributes\":{\"start\":0},\"id\":\"1378\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1407\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1392\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1397\"}},\"id\":\"1393\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1394\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1395\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1396\",\"type\":\"HelpTool\"},{\"attributes\":{\"tools\":[{\"id\":\"1391\"},{\"id\":\"1392\"},{\"id\":\"1393\"},{\"id\":\"1394\"},{\"id\":\"1395\"},{\"id\":\"1396\"}]},\"id\":\"1398\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1397\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1448\"},\"group\":null,\"major_label_policy\":{\"id\":\"1449\"},\"ticker\":{\"id\":\"1385\"}},\"id\":\"1384\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1445\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"1373\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"dddafc83-2e0c-4b39-b254-6676fec097da\",\"root_ids\":[\"1373\"],\"roots\":{\"1373\":\"e3f577a8-d62e-4798-8eeb-b39164d87341\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1373"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github标星数量\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Star'] , width=0.8, color=Spectral6) \n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践（2）2019年7月常见可视化工具Github标星数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"8c02a2df-d3e9-43a1-9f03-b089ece4da24\" data-root-id=\"1503\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"9d9efacc-9eac-4a0c-8dcd-762aef6f4b18\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1514\"}],\"center\":[{\"id\":\"1516\"},{\"id\":\"1520\"}],\"left\":[{\"id\":\"1517\"}],\"renderers\":[{\"id\":\"1539\"}],\"title\":{\"id\":\"1504\"},\"toolbar\":{\"id\":\"1528\"},\"x_range\":{\"id\":\"1506\"},\"x_scale\":{\"id\":\"1510\"},\"y_range\":{\"id\":\"1508\"},\"y_scale\":{\"id\":\"1512\"}},\"id\":\"1503\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1521\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1522\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1537\",\"type\":\"VBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1527\"}},\"id\":\"1523\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1591\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1524\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1588\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1525\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1586\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1526\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1510\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"start\":0},\"id\":\"1508\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1585\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1527\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"hatch_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[808,357,18,98,76,184],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1591\"},\"selection_policy\":{\"id\":\"1590\"}},\"id\":\"1535\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"tools\":[{\"id\":\"1521\"},{\"id\":\"1522\"},{\"id\":\"1523\"},{\"id\":\"1524\"},{\"id\":\"1525\"},{\"id\":\"1526\"}]},\"id\":\"1528\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1590\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1589\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1588\"},\"group\":null,\"major_label_policy\":{\"id\":\"1589\"},\"ticker\":{\"id\":\"1515\"}},\"id\":\"1514\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"2019\\u5e745\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u6e90\\u7801Github\\u8d21\\u732e\\u8005\\u4eba\\u6570\"},\"id\":\"1504\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1512\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1515\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1517\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1520\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1535\"},\"glyph\":{\"id\":\"1536\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1538\"},\"nonselection_glyph\":{\"id\":\"1537\"},\"view\":{\"id\":\"1540\"}},\"id\":\"1539\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1518\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"fill_color\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1538\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1506\",\"type\":\"FactorRange\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1585\"},\"group\":null,\"major_label_policy\":{\"id\":\"1586\"},\"ticker\":{\"id\":\"1518\"}},\"id\":\"1517\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1536\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1514\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1516\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1535\"}},\"id\":\"1540\",\"type\":\"CDSView\"}],\"root_ids\":[\"1503\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"9d9efacc-9eac-4a0c-8dcd-762aef6f4b18\",\"root_ids\":[\"1503\"],\"roots\":{\"1503\":\"8c02a2df-d3e9-43a1-9f03-b089ece4da24\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1503"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年5月常见可视化工具源码Github贡献者人数\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Contributors'] , width=0.8, color=Spectral6) # Commits\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践（3）2019年5月常见可视化工具源码Github提交次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"368c072b-aa6d-4006-96fb-d0afd8ee9fa7\" data-root-id=\"1643\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"84b76ca6-b345-4243-a304-26af9f257c27\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1654\"}],\"center\":[{\"id\":\"1656\"},{\"id\":\"1660\"}],\"left\":[{\"id\":\"1657\"}],\"renderers\":[{\"id\":\"1679\"}],\"title\":{\"id\":\"1644\"},\"toolbar\":{\"id\":\"1668\"},\"x_range\":{\"id\":\"1646\"},\"x_scale\":{\"id\":\"1650\"},\"y_range\":{\"id\":\"1648\"},\"y_scale\":{\"id\":\"1652\"}},\"id\":\"1643\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1677\",\"type\":\"VBar\"},{\"attributes\":{\"start\":0},\"id\":\"1648\",\"type\":\"DataRange1d\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1646\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1741\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1661\",\"type\":\"PanTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"2019\\u5e745\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u6e90\\u7801Github\\u63d0\\u4ea4\\u6b21\\u6570\"},\"id\":\"1644\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1662\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"hatch_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[29503,17673,1321,2316,3370,4286],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1741\"},\"selection_policy\":{\"id\":\"1740\"}},\"id\":\"1675\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"overlay\":{\"id\":\"1667\"}},\"id\":\"1663\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1664\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1665\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1739\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1735\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1666\",\"type\":\"HelpTool\"},{\"attributes\":{\"axis\":{\"id\":\"1657\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1660\",\"type\":\"Grid\"},{\"attributes\":{\"tools\":[{\"id\":\"1661\"},{\"id\":\"1662\"},{\"id\":\"1663\"},{\"id\":\"1664\"},{\"id\":\"1665\"},{\"id\":\"1666\"}]},\"id\":\"1668\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1652\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1650\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1667\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1655\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1675\"},\"glyph\":{\"id\":\"1676\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1678\"},\"nonselection_glyph\":{\"id\":\"1677\"},\"view\":{\"id\":\"1680\"}},\"id\":\"1679\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1740\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1738\"},\"group\":null,\"major_label_policy\":{\"id\":\"1739\"},\"ticker\":{\"id\":\"1655\"}},\"id\":\"1654\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1736\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis\":{\"id\":\"1654\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1656\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"fill_color\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1678\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1658\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"hatch_color\":{\"field\":\"hatch_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1676\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1738\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1735\"},\"group\":null,\"major_label_policy\":{\"id\":\"1736\"},\"ticker\":{\"id\":\"1658\"}},\"id\":\"1657\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"1675\"}},\"id\":\"1680\",\"type\":\"CDSView\"}],\"root_ids\":[\"1643\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"84b76ca6-b345-4243-a304-26af9f257c27\",\"root_ids\":[\"1643\"],\"roots\":{\"1643\":\"368c072b-aa6d-4006-96fb-d0afd8ee9fa7\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1643"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年5月常见可视化工具源码Github提交次数\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Commits'] , width=0.8, color=Spectral6) # Fork\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 颜色映射(细节)\n",
    "#### [factor_cmap](https://docs.bokeh.org/en/latest/docs/reference/transform.html)\n",
    "*  [bokeh.palettes：调色板](https://docs.bokeh.org/en/latest/docs/reference/palettes.html)\n",
    "\n",
    "#### 图例设置\n",
    "```\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.legend.location = \"top_center\"\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "??factor_cmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"de1127b1-0ff6-46df-bed1-ffe8070835d9\" data-root-id=\"2555\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"c7cba156-4c26-4285-9267-01f24a0f7c14\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2566\"}],\"center\":[{\"id\":\"2568\"},{\"id\":\"2572\"},{\"id\":\"2604\"}],\"height\":350,\"left\":[{\"id\":\"2569\"}],\"renderers\":[{\"id\":\"2592\"}],\"title\":{\"id\":\"2556\"},\"toolbar\":{\"id\":\"2580\"},\"x_range\":{\"id\":\"2558\"},\"x_scale\":{\"id\":\"2562\"},\"y_range\":{\"id\":\"2560\"},\"y_scale\":{\"id\":\"2564\"}},\"id\":\"2555\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2599\"},\"group\":null,\"major_label_policy\":{\"id\":\"2600\"},\"ticker\":{\"id\":\"2567\"}},\"id\":\"2566\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"2566\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"2568\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2596\"},\"group\":null,\"major_label_policy\":{\"id\":\"2597\"},\"ticker\":{\"id\":\"2570\"}},\"id\":\"2569\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fruits\",\"transform\":{\"id\":\"2587\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"2590\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2570\",\"type\":\"BasicTicker\"},{\"attributes\":{\"tools\":[{\"id\":\"2573\"},{\"id\":\"2574\"},{\"id\":\"2575\"},{\"id\":\"2576\"},{\"id\":\"2577\"},{\"id\":\"2578\"}]},\"id\":\"2580\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"fruits\",\"transform\":{\"id\":\"2587\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"2591\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"2569\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2572\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2554\"},\"glyph\":{\"id\":\"2589\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2591\"},\"nonselection_glyph\":{\"id\":\"2590\"},\"view\":{\"id\":\"2593\"}},\"id\":\"2592\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2597\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"2596\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2573\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2599\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"2564\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2574\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2579\"}},\"id\":\"2575\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2562\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_color\":{\"field\":\"fruits\",\"transform\":{\"id\":\"2587\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"2589\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2554\"}},\"id\":\"2593\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2576\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"2600\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts\"},\"id\":\"2556\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2577\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2578\",\"type\":\"HelpTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"2605\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"2604\",\"type\":\"Legend\"},{\"attributes\":{\"end\":9,\"start\":0},\"id\":\"2560\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2601\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2602\",\"type\":\"Selection\"},{\"attributes\":{\"label\":{\"field\":\"fruits\"},\"renderers\":[{\"id\":\"2592\"}]},\"id\":\"2605\",\"type\":\"LegendItem\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"2558\",\"type\":\"FactorRange\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2579\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"],\"palette\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"]},\"id\":\"2587\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"2567\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"fruits\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"2602\"},\"selection_policy\":{\"id\":\"2601\"}},\"id\":\"2554\",\"type\":\"ColumnDataSource\"}],\"root_ids\":[\"2555\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"c7cba156-4c26-4285-9267-01f24a0f7c14\",\"root_ids\":[\"2555\"],\"roots\":{\"2555\":\"de1127b1-0ff6-46df-bed1-ffe8070835d9\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2555"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral5\n",
    "from bokeh.transform import factor_cmap\n",
    "# 数据\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "source = ColumnDataSource(data=dict(fruits=fruits, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=fruits, plot_height=350, \n",
    "#            toolbar_location=None,\n",
    "           title=\"Fruit Counts\")\n",
    "# 绘图，分组颜色映射\n",
    "p.vbar(x='fruits', top='counts', width=0.9, source=source, legend=\"fruits\",\n",
    "       line_color='white', fill_color=factor_cmap('fruits', palette=Spectral6, factors=fruits))\n",
    "# 坐标轴、图例设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.y_range.end = 9\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.legend.location = \"top_center\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"e180d019-0f72-459e-8b5b-3508d769670f\" data-root-id=\"2769\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"ee75a713-7a28-4398-9ea8-d94ad7e8c592\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2780\"}],\"center\":[{\"id\":\"2783\"},{\"id\":\"2786\"},{\"id\":\"2817\"}],\"height\":250,\"left\":[{\"id\":\"2784\"}],\"renderers\":[{\"id\":\"2805\"}],\"title\":{\"id\":\"2770\"},\"toolbar\":{\"id\":\"2794\"},\"x_range\":{\"id\":\"2772\"},\"x_scale\":{\"id\":\"2776\"},\"y_range\":{\"id\":\"2774\"},\"y_scale\":{\"id\":\"2778\"}},\"id\":\"2769\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"axis\":{\"id\":\"2780\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"2783\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2814\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"color\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"field\":\"color\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"color\"},\"right\":{\"field\":\"counts\"},\"y\":{\"field\":\"fruits\"}},\"id\":\"2804\",\"type\":\"HBar\"},{\"attributes\":{\"axis\":{\"id\":\"2784\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2786\",\"type\":\"Grid\"},{\"attributes\":{\"label\":{\"field\":\"fruits\"},\"renderers\":[{\"id\":\"2805\"}]},\"id\":\"2818\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2792\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"2778\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"2781\",\"type\":\"BasicTicker\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"2774\",\"type\":\"FactorRange\"},{\"attributes\":{\"end\":9},\"id\":\"2772\",\"type\":\"Range1d\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2768\"},\"glyph\":{\"id\":\"2802\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2804\"},\"nonselection_glyph\":{\"id\":\"2803\"},\"view\":{\"id\":\"2806\"}},\"id\":\"2805\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2793\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2787\",\"type\":\"PanTool\"},{\"attributes\":{\"source\":{\"id\":\"2768\"}},\"id\":\"2806\",\"type\":\"CDSView\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"counts\":[5,3,4,2,4,6],\"fruits\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"2815\"},\"selection_policy\":{\"id\":\"2814\"}},\"id\":\"2768\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"hatch_color\":{\"field\":\"color\"},\"height\":{\"value\":0.5},\"line_color\":{\"field\":\"color\"},\"right\":{\"field\":\"counts\"},\"y\":{\"field\":\"fruits\"}},\"id\":\"2802\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"2813\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"2776\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2815\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2785\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2812\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"field\":\"color\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"right\":{\"field\":\"counts\"},\"y\":{\"field\":\"fruits\"}},\"id\":\"2803\",\"type\":\"HBar\"},{\"attributes\":{\"tools\":[{\"id\":\"2787\"},{\"id\":\"2788\"},{\"id\":\"2789\"},{\"id\":\"2790\"},{\"id\":\"2791\"},{\"id\":\"2792\"}]},\"id\":\"2794\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2788\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts\"},\"id\":\"2770\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2810\",\"type\":\"AllLabels\"},{\"attributes\":{\"overlay\":{\"id\":\"2793\"}},\"id\":\"2789\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2791\",\"type\":\"ResetTool\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2809\"},\"group\":null,\"major_label_policy\":{\"id\":\"2810\"},\"ticker\":{\"id\":\"2785\"}},\"id\":\"2784\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"2818\"}]},\"id\":\"2817\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"2809\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2812\"},\"group\":null,\"major_label_policy\":{\"id\":\"2813\"},\"ticker\":{\"id\":\"2781\"}},\"id\":\"2780\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2790\",\"type\":\"SaveTool\"}],\"root_ids\":[\"2769\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"ee75a713-7a28-4398-9ea8-d94ad7e8c592\",\"root_ids\":[\"2769\"],\"roots\":{\"2769\":\"e180d019-0f72-459e-8b5b-3508d769670f\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2769"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6  # ['#3288bd', '#99d594', '#e6f598', '#fee08b', '#fc8d59', '#d53e4f']\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "source = ColumnDataSource(data=dict(fruits=fruits, counts=counts, color=Spectral6))\n",
    "p = figure(x_range=(0,9), y_range=fruits, plot_height=250, title=\"Fruit Counts\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "p.hbar(y='fruits',left=0,right='counts', height=0.5 ,color='color', legend=\"fruits\", source=source)\n",
    "p.xgrid.grid_line_color = None\n",
    "# p.legend.orientation = \"horizontal\"\n",
    "p.legend.location = \"top_right\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"85b8bb6d-d9f6-4a2a-a025-411e276c3860\" data-root-id=\"3736\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"670c632d-4acf-473e-a90a-7f060733917d\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3746\"}],\"center\":[{\"id\":\"3748\"},{\"id\":\"3752\"}],\"height\":350,\"left\":[{\"id\":\"3749\"}],\"renderers\":[{\"id\":\"3771\"}],\"title\":{\"id\":\"3737\"},\"toolbar\":{\"id\":\"3760\"},\"x_range\":{\"id\":\"3735\"},\"x_scale\":{\"id\":\"3742\"},\"y_range\":{\"id\":\"3740\"},\"y_scale\":{\"id\":\"3744\"}},\"id\":\"3736\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3927\"},\"group\":null,\"major_label_policy\":{\"id\":\"3928\"},\"ticker\":{\"id\":\"3750\"}},\"id\":\"3749\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3768\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"3734\"}},\"id\":\"3772\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"3749\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"3752\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3734\"},\"glyph\":{\"id\":\"3768\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"3770\"},\"nonselection_glyph\":{\"id\":\"3769\"},\"view\":{\"id\":\"3772\"}},\"id\":\"3771\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3754\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"3740\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"3932\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"3927\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3753\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"3757\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"3933\"},\"selection_policy\":{\"id\":\"3932\"}},\"id\":\"3734\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts by Year\"},\"id\":\"3737\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"3759\"}},\"id\":\"3755\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"3756\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"3744\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"3758\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3742\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"3759\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"3750\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3931\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"3933\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"3746\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"3748\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3930\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"3931\"},\"ticker\":{\"id\":\"3747\"}},\"id\":\"3746\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"3747\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"3928\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"3930\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"tools\":[{\"id\":\"3753\"},{\"id\":\"3754\"},{\"id\":\"3755\"},{\"id\":\"3756\"},{\"id\":\"3757\"},{\"id\":\"3758\"}]},\"id\":\"3760\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3770\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"3735\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3769\",\"type\":\"VBar\"}],\"root_ids\":[\"3736\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"670c632d-4acf-473e-a90a-7f060733917d\",\"root_ids\":[\"3736\"],\"roots\":{\"3736\":\"85b8bb6d-d9f6-4a2a-a025-411e276c3860\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3736"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Apples', '2015'),\n",
       " ('Apples', '2016'),\n",
       " ('Apples', '2017'),\n",
       " ('Pears', '2015'),\n",
       " ('Pears', '2016'),\n",
       " ('Pears', '2017'),\n",
       " ('Nectarines', '2015'),\n",
       " ('Nectarines', '2016'),\n",
       " ('Nectarines', '2017'),\n",
       " ('Plums', '2015'),\n",
       " ('Plums', '2016'),\n",
       " ('Plums', '2017'),\n",
       " ('Grapes', '2015'),\n",
       " ('Grapes', '2016'),\n",
       " ('Grapes', '2017'),\n",
       " ('Strawberries', '2015'),\n",
       " ('Strawberries', '2016'),\n",
       " ('Strawberries', '2017')]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"21186fc3-21dd-497a-ace5-33ae8e4d000d\" data-root-id=\"3987\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"ab247ad6-1bd6-4519-9707-70f643c51eed\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3997\"}],\"center\":[{\"id\":\"3999\"},{\"id\":\"4003\"}],\"height\":350,\"left\":[{\"id\":\"4000\"}],\"renderers\":[{\"id\":\"4023\"}],\"title\":{\"id\":\"3988\"},\"toolbar\":{\"id\":\"4011\"},\"x_range\":{\"id\":\"3986\"},\"x_scale\":{\"id\":\"3993\"},\"y_range\":{\"id\":\"3991\"},\"y_scale\":{\"id\":\"3995\"}},\"id\":\"3987\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3985\"},\"glyph\":{\"id\":\"4020\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"4022\"},\"nonselection_glyph\":{\"id\":\"4021\"},\"view\":{\"id\":\"4024\"}},\"id\":\"4023\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"4189\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"4195\",\"type\":\"Selection\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts by Year\"},\"id\":\"3988\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"4004\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"4008\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"4001\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"4189\"},\"group\":null,\"major_label_policy\":{\"id\":\"4190\"},\"ticker\":{\"id\":\"4001\"}},\"id\":\"4000\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"4195\"},\"selection_policy\":{\"id\":\"4194\"}},\"id\":\"3985\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"4000\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"4003\",\"type\":\"Grid\"},{\"attributes\":{\"tools\":[{\"id\":\"4004\"},{\"id\":\"4005\"},{\"id\":\"4006\"},{\"id\":\"4007\"},{\"id\":\"4008\"},{\"id\":\"4009\"}]},\"id\":\"4011\",\"type\":\"Toolbar\"},{\"attributes\":{\"overlay\":{\"id\":\"4010\"}},\"id\":\"4006\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"3997\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"3999\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"4007\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"4005\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"4018\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"4020\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"4194\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"end\":2,\"factors\":[\"2015\",\"2016\",\"2017\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"4018\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"4018\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"4022\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"4192\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"4193\"},\"ticker\":{\"id\":\"3998\"}},\"id\":\"3997\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"4190\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"4009\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"4018\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"4021\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"3986\",\"type\":\"FactorRange\"},{\"attributes\":{\"start\":0},\"id\":\"3991\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"3993\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"4010\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"3985\"}},\"id\":\"4024\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3998\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"4192\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"4193\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"3995\",\"type\":\"LinearScale\"}],\"root_ids\":[\"3987\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"ab247ad6-1bd6-4519-9707-70f643c51eed\",\"root_ids\":[\"3987\"],\"roots\":{\"3987\":\"21186fc3-21dd-497a-ace5-33ae8e4d000d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3987"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "palette = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "display(x)\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # like an hstack\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source, line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=years, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"83efe419-afdc-409e-a7ba-d2790f6c2095\" data-root-id=\"3445\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"8944c401-332b-440d-b996-34ebade77770\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3456\"}],\"center\":[{\"id\":\"3458\"},{\"id\":\"3462\"},{\"id\":\"3494\"}],\"height\":350,\"left\":[{\"id\":\"3459\"}],\"renderers\":[{\"id\":\"3482\"},{\"id\":\"3501\"},{\"id\":\"3519\"}],\"title\":{\"id\":\"3446\"},\"toolbar\":{\"id\":\"3470\"},\"x_range\":{\"id\":\"3448\"},\"x_scale\":{\"id\":\"3452\"},\"y_range\":{\"id\":\"3450\"},\"y_scale\":{\"id\":\"3454\"}},\"id\":\"3445\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"3466\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis\":{\"id\":\"3456\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"3458\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3467\",\"type\":\"ResetTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#718dbf\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"#718dbf\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"2016\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3496\"}}},\"id\":\"3500\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"],\"range_padding\":0.1},\"id\":\"3448\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"3468\",\"type\":\"HelpTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts by Year\"},\"id\":\"3446\",\"type\":\"Title\"},{\"attributes\":{\"tools\":[{\"id\":\"3463\"},{\"id\":\"3464\"},{\"id\":\"3465\"},{\"id\":\"3466\"},{\"id\":\"3467\"},{\"id\":\"3468\"}]},\"id\":\"3470\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#718dbf\"},\"hatch_color\":{\"value\":\"#718dbf\"},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"2016\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3496\"}}},\"id\":\"3498\",\"type\":\"VBar\"},{\"attributes\":{\"end\":10},\"id\":\"3450\",\"type\":\"Range1d\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"3469\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"3469\"}},\"id\":\"3465\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"3452\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"range\":{\"id\":\"3448\"},\"value\":0.25},\"id\":\"3514\",\"type\":\"Dodge\"},{\"attributes\":{},\"id\":\"3454\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3444\"},\"glyph\":{\"id\":\"3479\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"3481\"},\"nonselection_glyph\":{\"id\":\"3480\"},\"view\":{\"id\":\"3483\"}},\"id\":\"3482\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#e84d60\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"#e84d60\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"2017\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3514\"}}},\"id\":\"3518\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3457\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#c9d9d3\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"#c9d9d3\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"2015\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3477\"}}},\"id\":\"3481\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3489\"},\"group\":null,\"major_label_policy\":{\"id\":\"3490\"},\"ticker\":{\"id\":\"3457\"}},\"id\":\"3456\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"source\":{\"id\":\"3444\"}},\"id\":\"3520\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"2017\"},\"renderers\":[{\"id\":\"3519\"}]},\"id\":\"3531\",\"type\":\"LegendItem\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"3495\"},{\"id\":\"3513\"},{\"id\":\"3531\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"3494\",\"type\":\"Legend\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3486\"},\"group\":null,\"major_label_policy\":{\"id\":\"3487\"},\"ticker\":{\"id\":\"3460\"}},\"id\":\"3459\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"hatch_color\":{\"value\":\"#c9d9d3\"},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"2015\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3477\"}}},\"id\":\"3479\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3460\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3487\",\"type\":\"AllLabels\"},{\"attributes\":{\"source\":{\"id\":\"3444\"}},\"id\":\"3483\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"3459\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"3462\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3489\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"#c9d9d3\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"2015\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3477\"}}},\"id\":\"3480\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3444\"},\"glyph\":{\"id\":\"3516\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"3518\"},\"nonselection_glyph\":{\"id\":\"3517\"},\"view\":{\"id\":\"3520\"}},\"id\":\"3519\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"label\":{\"value\":\"2016\"},\"renderers\":[{\"id\":\"3501\"}]},\"id\":\"3513\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"3486\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"2015\"},\"renderers\":[{\"id\":\"3482\"}]},\"id\":\"3495\",\"type\":\"LegendItem\"},{\"attributes\":{\"data\":{\"2015\":[2,1,4,3,2,4],\"2016\":[5,3,3,2,4,6],\"2017\":[3,2,4,4,5,3],\"fruits\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"3492\"},\"selection_policy\":{\"id\":\"3491\"}},\"id\":\"3444\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"range\":{\"id\":\"3448\"}},\"id\":\"3496\",\"type\":\"Dodge\"},{\"attributes\":{},\"id\":\"3490\",\"type\":\"AllLabels\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#718dbf\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"#718dbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"2016\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3496\"}}},\"id\":\"3499\",\"type\":\"VBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#e84d60\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"#e84d60\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"2017\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3514\"}}},\"id\":\"3517\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3463\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"3491\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"range\":{\"id\":\"3448\"},\"value\":-0.25},\"id\":\"3477\",\"type\":\"Dodge\"},{\"attributes\":{},\"id\":\"3464\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"3492\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"3444\"}},\"id\":\"3502\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"value\":\"#e84d60\"},\"hatch_color\":{\"value\":\"#e84d60\"},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"2017\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"fruits\",\"transform\":{\"id\":\"3514\"}}},\"id\":\"3516\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3444\"},\"glyph\":{\"id\":\"3498\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"3500\"},\"nonselection_glyph\":{\"id\":\"3499\"},\"view\":{\"id\":\"3502\"}},\"id\":\"3501\",\"type\":\"GlyphRenderer\"}],\"root_ids\":[\"3445\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"8944c401-332b-440d-b996-34ebade77770\",\"root_ids\":[\"3445\"],\"roots\":{\"3445\":\"83efe419-afdc-409e-a7ba-d2790f6c2095\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3445"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.core.properties import value\n",
    "from bokeh.transform import dodge  \n",
    "# 数据\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "source = ColumnDataSource(data=data)\n",
    "# 画布\n",
    "p = figure(x_range=fruits, y_range=(0, 10), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图，采用doge数据转换，按产品种类不同年份分组显示\n",
    "p.vbar(x=dodge('fruits', -0.25, range=p.x_range), top='2015', width=0.2, source=source,\n",
    "       color=\"#c9d9d3\", legend=value(\"2015\"))\n",
    "\n",
    "p.vbar(x=dodge('fruits',  0.0,  range=p.x_range), top='2016', width=0.2, source=source,\n",
    "       color=\"#718dbf\", legend=value(\"2016\"))\n",
    "\n",
    "p.vbar(x=dodge('fruits',  0.25, range=p.x_range), top='2017', width=0.2, source=source,\n",
    "       color=\"#e84d60\", legend=value(\"2017\"))\n",
    "# 其他参数设置\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"f8930844-1c84-40a5-9ed6-37f4b0130662\" data-root-id=\"4248\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"5f4c7b54-f15e-466c-b0cc-e045ebdacf8f\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"4259\"}],\"center\":[{\"id\":\"4261\"},{\"id\":\"4265\"}],\"height\":350,\"left\":[{\"id\":\"4262\"}],\"outline_line_color\":null,\"renderers\":[{\"id\":\"4285\"}],\"title\":{\"id\":\"4249\"},\"toolbar\":{\"id\":\"4273\"},\"x_range\":{\"id\":\"4251\"},\"x_scale\":{\"id\":\"4255\"},\"y_range\":{\"id\":\"4253\"},\"y_scale\":{\"id\":\"4257\"}},\"id\":\"4248\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"4461\"},\"group\":null,\"major_label_policy\":{\"id\":\"4462\"},\"ticker\":{\"id\":\"4263\"}},\"id\":\"4262\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"4263\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"4262\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"4265\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[\"3\",\"4\",\"5\",\"6\",\"8\"],\"palette\":[\"#2b83ba\",\"#abdda4\",\"#ffffbf\",\"#fdae61\",\"#d7191c\"]},\"id\":\"4247\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"4466\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"accel_25%\":{\"__ndarray__\":\"AAAAAACAKkCamZmZmZktQGZmZmZm5jFAmpmZmZkZLkAAAAAAAAAnQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_50%\":{\"__ndarray__\":\"AAAAAAAAK0AzMzMzMzMwQGZmZmZm5jNAAAAAAAAAMEAAAAAAAAAqQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_75%\":{\"__ndarray__\":\"AAAAAAAAK0AAAAAAAAAyQAAAAAAAADRAmpmZmZmZMUAAAAAAAAAsQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_max\":{\"__ndarray__\":\"AAAAAAAAK0DNzMzMzMw4QJqZmZmZGTRAAAAAAAAANUAzMzMzMzM2QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_mean\":{\"__ndarray__\":\"AAAAAACAKkCSxCwG+JQwQCIiIiIiojJA7d9LWxRBMEBCLI1MIukpQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_min\":{\"__ndarray__\":\"AAAAAAAAKUAzMzMzMzMnQM3MzMzMzC9AmpmZmZmZJkAAAAAAAAAgQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"accel_std\":{\"__ndarray__\":\"AAAAAAAA4D+Y1TA5wxADQO1jrP039AJA0StM4BRBAEABZ5ysTswBQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"cyl\":[\"3\",\"4\",\"5\",\"6\",\"8\"],\"displ_25%\":{\"__ndarray__\":\"AAAAAACAUUAAAAAAAMBWQAAAAAAAgF9AAAAAAADwaEAAAAAAABBzQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_50%\":{\"__ndarray__\":\"AAAAAACAUUAAAAAAAEBaQAAAAAAAYGBAAAAAAADgbEAAAAAAAOB1QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_75%\":{\"__ndarray__\":\"AAAAAAAgUkAAAAAAAEBeQAAAAAAAoGNAAAAAAABAb0AAAAAAAIB2QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_max\":{\"__ndarray__\":\"AAAAAAAAVEAAAAAAAIBjQAAAAAAA4GZAAAAAAABgcEAAAAAAAHB8QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_mean\":{\"__ndarray__\":\"AAAAAAAgUkD/9sBG72pbQAAAAAAAIGJAmjq/9pBLa0DJeVnEJ5B1QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_min\":{\"__ndarray__\":\"AAAAAACAUUAAAAAAAABRQAAAAAAAQF5AAAAAAAAgYkAAAAAAAEBwQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"displ_std\":{\"__ndarray__\":\"AAAAAAAAFEC9furRdmA1QLmT4WuwpEBAT4BvAbA2QEDXs8ZGYGNHQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_25%\":{\"__ndarray__\":\"AAAAAADQV0AAAAAAAABRQAAAAAAAAFJAAAAAAAAgV0AAAAAAAIBhQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_50%\":{\"__ndarray__\":\"AAAAAACgWEAAAAAAAIBTQAAAAAAAQFNAAAAAAAAAWUAAAAAAAMBiQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_75%\":{\"__ndarray__\":\"AAAAAACgWUAAAAAAAABWQAAAAAAAgFZAAAAAAACAW0AAAAAAAOBlQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_max\":{\"__ndarray__\":\"AAAAAACAW0AAAAAAAMBcQAAAAAAAwFlAAAAAAACgZEAAAAAAAMBsQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_mean\":{\"__ndarray__\":\"AAAAAADQWEB2PKeSApJTQFVVVVVVlVRAsD3ksmJgWUDCfquNocljQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_min\":{\"__ndarray__\":\"AAAAAACAVkAAAAAAAABHQAAAAAAAwFBAAAAAAAAAUkAAAAAAAIBWQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"hp_std\":{\"__ndarray__\":\"sTIWI2yaIECEr0Go0wstQDKsjxZJlTJAxZAwIvaeLEBPwZb3G3Q8QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_25%\":{\"__ndarray__\":\"AAAAAADAMkAAAAAAAAA5QJqZmZmZ2TZAAAAAAAAAMkAAAAAAAAAqQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_50%\":{\"__ndarray__\":\"AAAAAABANEBmZmZmZmY8QGZmZmZmZjlAAAAAAAAAM0AAAAAAAAAsQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_75%\":{\"__ndarray__\":\"zczMzMwMNkCamZmZmXlAQGZmZmZm5j5AAAAAAAAANUAAAAAAAAAwQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_max\":{\"__ndarray__\":\"MzMzMzOzN0DNzMzMzExHQDMzMzMzM0JAAAAAAAAAQ0CamZmZmZk6QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_mean\":{\"__ndarray__\":\"zczMzMyMNEByD2z0rkg9QN3d3d3dXTtA6lu15jb5M0BhwH9VHO0tQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_min\":{\"__ndarray__\":\"AAAAAAAAMkAAAAAAAAAyQM3MzMzMTDRAAAAAAAAALkAAAAAAAAAiQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"mpg_std\":{\"__ndarray__\":\"ca9eOxmEBECNLXOmo64WQOWG1RfXdCBALURKf2ahDkC3cW7BtbAGQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_25%\":{\"__ndarray__\":\"AAAAAAAACEAAAAAAAADwPwAAAAAAAABAAAAAAAAA8D8AAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_50%\":{\"__ndarray__\":\"AAAAAAAACEAAAAAAAAAAQAAAAAAAAABAAAAAAAAA8D8AAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_75%\":{\"__ndarray__\":\"AAAAAAAACEAAAAAAAAAIQAAAAAAAAABAAAAAAAAA8D8AAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_max\":{\"__ndarray__\":\"AAAAAAAACEAAAAAAAAAIQAAAAAAAAABAAAAAAAAACEAAAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_mean\":{\"__ndarray__\":\"AAAAAAAACEAAAAAAAAAAQAAAAAAAAABAdX7tIZcV8z8AAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_min\":{\"__ndarray__\":\"AAAAAAAACEAAAAAAAADwPwAAAAAAAABAAAAAAAAA8D8AAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"origin_std\":{\"__ndarray__\":\"AAAAAAAAAACo00pJEbfqPwAAAAAAAAAAPS9VpaOj4T8AAAAAAAAAAA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_25%\":{\"__ndarray__\":\"AAAAAADNoUAAAAAAAP6fQAAAAAAAlKZAAAAAAAACp0AAAAAAAK6tQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_50%\":{\"__ndarray__\":\"AAAAAACOokAAAAAAAGyhQAAAAAAADKdAAAAAAAAUqUAAAAAAACywQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_75%\":{\"__ndarray__\":\"AAAAAAB+o0AAAAAAAAWkQAAAAAAAUKlAAAAAAADOqkAAAAAAgDOxQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_max\":{\"__ndarray__\":\"AAAAAABApUAAAAAAAIypQAAAAAAAlKtAAAAAAACGrkAAAAAAABS0QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_mean\":{\"__ndarray__\":\"AAAAAAC9okAsMl+aOAKiQKuqqqqqPqhAjqbOrz0EqUBD0x3stxKwQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_min\":{\"__ndarray__\":\"AAAAAACYoEAAAAAAADSZQAAAAAAAHKZAAAAAAABQo0AAAAAAAByoQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"weight_std\":{\"__ndarray__\":\"udhs7B3ybkC7+VSg9G11QA9pSX6AZXdAdmeNgiLGdEC9UR6eVA18QA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_25%\":{\"__ndarray__\":\"AAAAAAAwUkAAAAAAAIBSQAAAAAAAoFNAAAAAAACAUkAAAAAAAABSQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_50%\":{\"__ndarray__\":\"AAAAAADAUkAAAAAAAEBTQAAAAAAAwFNAAAAAAAAAU0AAAAAAAEBSQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_75%\":{\"__ndarray__\":\"AAAAAABwU0AAAAAAAABUQAAAAAAA4FNAAAAAAACAU0AAAAAAAABTQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAOBoQAAAAAAAAAhAAAAAAADAVEAAAAAAAMBZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_max\":{\"__ndarray__\":\"AAAAAAAAVEAAAAAAAIBUQAAAAAAAAFRAAAAAAACAVEAAAAAAAEBUQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_mean\":{\"__ndarray__\":\"AAAAAADgUkDEWG397UFTQAAAAAAAwFNAghLeaOr8UkCL+ARSyXlSQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_min\":{\"__ndarray__\":\"AAAAAAAAUkAAAAAAAIBRQAAAAAAAgFNAAAAAAACAUUAAAAAAAIBRQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]},\"yr_std\":{\"__ndarray__\":\"p1MQvCOTDUAe5PLGXeYNQAAAAAAAAPA/p0OY+nMdCkABv1x2cisIQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[5]}},\"selected\":{\"id\":\"4467\"},\"selection_policy\":{\"id\":\"4466\"}},\"id\":\"4280\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"4266\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"4464\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"4267\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"4253\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"4462\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"MPG by # Cylinders\"},\"id\":\"4249\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"4461\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"4272\"}},\"id\":\"4268\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"4269\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"4270\",\"type\":\"ResetTool\"},{\"attributes\":{\"factors\":[\"3\",\"4\",\"5\",\"6\",\"8\"]},\"id\":\"4251\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"cyl\",\"transform\":{\"id\":\"4247\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"cyl\",\"transform\":{\"id\":\"4247\"}},\"top\":{\"field\":\"mpg_mean\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"cyl\"}},\"id\":\"4283\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"4271\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"4467\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"4280\"}},\"id\":\"4286\",\"type\":\"CDSView\"},{\"attributes\":{\"tools\":[{\"id\":\"4266\"},{\"id\":\"4267\"},{\"id\":\"4268\"},{\"id\":\"4269\"},{\"id\":\"4270\"},{\"id\":\"4271\"}]},\"id\":\"4273\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"field\":\"cyl\",\"transform\":{\"id\":\"4247\"}},\"line_color\":{\"field\":\"cyl\",\"transform\":{\"id\":\"4247\"}},\"top\":{\"field\":\"mpg_mean\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"cyl\"}},\"id\":\"4282\",\"type\":\"VBar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"4272\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"4255\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"4257\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis_label\":\"some stuff\",\"coordinates\":null,\"formatter\":{\"id\":\"4464\"},\"group\":null,\"major_label_orientation\":1.2,\"major_label_policy\":{\"id\":\"4465\"},\"ticker\":{\"id\":\"4260\"}},\"id\":\"4259\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"4259\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"4261\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"4280\"},\"glyph\":{\"id\":\"4282\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"4284\"},\"nonselection_glyph\":{\"id\":\"4283\"},\"view\":{\"id\":\"4286\"}},\"id\":\"4285\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"4465\",\"type\":\"AllLabels\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"cyl\",\"transform\":{\"id\":\"4247\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"cyl\",\"transform\":{\"id\":\"4247\"}},\"top\":{\"field\":\"mpg_mean\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"cyl\"}},\"id\":\"4284\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"4260\",\"type\":\"CategoricalTicker\"}],\"root_ids\":[\"4248\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"5f4c7b54-f15e-466c-b0cc-e045ebdacf8f\",\"root_ids\":[\"4248\"],\"roots\":{\"4248\":\"f8930844-1c84-40a5-9ed6-37f4b0130662\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "4248"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral5\n",
    "from bokeh.sampledata.autompg import autompg as df\n",
    "from bokeh.transform import factor_cmap\n",
    "# 数据,预处理\n",
    "df.cyl = df.cyl.astype(str)\n",
    "group = df.groupby('cyl')\n",
    "cyl_cmap = factor_cmap('cyl', palette=Spectral5, factors=sorted(df.cyl.unique())) # 分组颜色映射\n",
    "# 画布\n",
    "p = figure(plot_height=350, x_range=group, title=\"MPG by # Cylinders\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图\n",
    "p.vbar(x='cyl', top='mpg_mean', width=0.9, source=group,\n",
    "       line_color=cyl_cmap, fill_color=cyl_cmap)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.xgrid.grid_line_color = None\n",
    "p.xaxis.axis_label = \"some stuff\"\n",
    "p.xaxis.major_label_orientation = 1.2\n",
    "p.outline_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 堆叠柱状图\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 瀑布图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"315ca884-0e14-4722-a15d-3137473c9752\" data-root-id=\"4520\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"b0af28e7-f787-4a33-b9da-0c0463d50ee7\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"4531\"}],\"center\":[{\"id\":\"4534\"},{\"id\":\"4537\"}],\"height\":550,\"left\":[{\"id\":\"4535\"}],\"outline_line_color\":null,\"renderers\":[{\"id\":\"4556\"}],\"title\":{\"id\":\"4521\"},\"toolbar\":{\"id\":\"4545\"},\"width\":400,\"x_range\":{\"id\":\"4523\"},\"x_scale\":{\"id\":\"4527\"},\"y_range\":{\"id\":\"4525\"},\"y_scale\":{\"id\":\"4529\"}},\"id\":\"4520\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"4747\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"4544\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"axis\":{\"id\":\"4531\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"4534\",\"type\":\"Grid\"},{\"attributes\":{\"end\":12.7,\"start\":9.5},\"id\":\"4523\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"4746\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"4542\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"4742\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[\"1896\",\"1900\",\"1904\",\"1906\",\"1908\",\"1912\",\"1920\",\"1924\",\"1928\",\"1932\",\"1936\",\"1948\",\"1952\",\"1956\",\"1960\",\"1964\",\"1968\",\"1972\",\"1976\",\"1980\",\"1984\",\"1988\",\"1992\",\"1996\",\"2000\",\"2004\",\"2008\",\"2012\"]},\"id\":\"4525\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"4529\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"4527\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"4543\",\"type\":\"HelpTool\"},{\"attributes\":{\"tools\":[{\"id\":\"4538\"},{\"id\":\"4539\"},{\"id\":\"4540\"},{\"id\":\"4541\"},{\"id\":\"4542\"},{\"id\":\"4543\"}]},\"id\":\"4545\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"4536\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"4519\"},\"glyph\":{\"id\":\"4553\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"4555\"},\"nonselection_glyph\":{\"id\":\"4554\"},\"view\":{\"id\":\"4557\"}},\"id\":\"4556\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"height\":{\"value\":0.4},\"left\":{\"field\":\"Time_min\"},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"Time_max\"},\"y\":{\"field\":\"Year\"}},\"id\":\"4553\",\"type\":\"HBar\"},{\"attributes\":{\"source\":{\"id\":\"4519\"}},\"id\":\"4557\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"4742\"},\"group\":null,\"major_label_policy\":{\"id\":\"4743\"},\"ticker\":{\"id\":\"4536\"}},\"id\":\"4535\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Time Spreads for Sprint Medalists (by Year)\"},\"id\":\"4521\",\"type\":\"Title\"},{\"attributes\":{\"axis_label\":\"Time (seconds)\",\"coordinates\":null,\"formatter\":{\"id\":\"4745\"},\"group\":null,\"major_label_policy\":{\"id\":\"4746\"},\"ticker\":{\"id\":\"4532\"}},\"id\":\"4531\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data\":{\"Time_25%\":{\"__ndarray__\":\"zMzMzMxMKECamZmZmRkmQDMzMzMzMyZAAAAAAACAJkDNzMzMzMwlQDQzMzMzsyVANDMzMzOzJUBmZmZmZmYlQDQzMzMzsyVAmpmZmZmZJEA0MzMzM7MkQDQzMzMzsyRAzczMzMzMJEAAAAAAAAAlQGZmZmZmZiRAMzMzMzMzJEA9CtejcP0jQOJ6FK5HYSRApHA9CtcjJEAAAAAAAIAkQK5H4XoULiRApHA9CtfjI0B7FK5H4fojQHsUrkfhuiNAXI/C9SjcI0D2KFyPwrUjQBSuR+F6lCNA4noUrkdhI0A=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_50%\":{\"__ndarray__\":\"zMzMzMzMKEAzMzMzMzMmQGZmZmZmZiZAmpmZmZmZJkAAAAAAAAAmQM3MzMzMzCVAzczMzMzMJUCamZmZmZklQM3MzMzMzCVAmpmZmZmZJEDNzMzMzMwkQM3MzMzMzCRAzczMzMzMJEAAAAAAAAAlQGZmZmZmZiRAZmZmZmZmJEAUrkfhehQkQHsUrkfheiRAKVyPwvUoJEAAAAAAAIAkQOF6FK5HYSRAcT0K16PwI0AK16NwPQokQEjhehSuxyNAexSuR+H6I0C4HoXrUbgjQEjhehSuxyNAAAAAAACAI0A=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_75%\":{\"__ndarray__\":\"MzMzMzMzKUDMzMzMzEwmQGZmZmZmZiZAmpmZmZmZJkAAAAAAAAAmQM3MzMzMzCVAzczMzMzMJUA0MzMzM7MlQM3MzMzMzCVANDMzMzOzJEBmZmZmZuYkQM3MzMzMzCRAzczMzMzMJECamZmZmRklQAAAAAAAgCRAZmZmZmZmJEBcj8L1KBwkQFK4HoXrkSRAuB6F61E4JECkcD0K16MkQClcj8L1aCRA9ihcj8L1I0CPwvUoXA8kQArXo3A9yiNASOF6FK4HJEB6FK5H4bojQM3MzMzMzCNACtejcD2KI0A=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_count\":{\"__ndarray__\":\"AAAAAAAAEEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAhAAAAAAAAACEA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_max\":{\"__ndarray__\":\"MzMzMzMzKUBmZmZmZmYmQGZmZmZmZiZAmpmZmZmZJkAAAAAAAAAmQM3MzMzMzCVAzczMzMzMJUDNzMzMzMwlQM3MzMzMzCVAzczMzMzMJEAAAAAAAAAlQM3MzMzMzCRAzczMzMzMJEAzMzMzMzMlQJqZmZmZmSRAZmZmZmZmJECkcD0K1yMkQClcj8L1qCRASOF6FK5HJEBI4XoUrsckQHE9CtejcCRAexSuR+H6I0AUrkfhehQkQM3MzMzMzCNAFK5H4XoUJEA9CtejcL0jQFK4HoXr0SNAFK5H4XqUI0A=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_mean\":{\"__ndarray__\":\"MzMzMzOzKEAzMzMzMzMmQERERERERCZAiIiIiIiIJkDd3d3d3d0lQLy7u7u7uyVAvLu7u7u7JUCIiIiIiIglQLy7u7u7uyVAq6qqqqqqJEDNzMzMzMwkQLy7u7u7uyRAzczMzMzMJEARERERERElQHd3d3d3dyRAREREREREJEAK16NwPQokQPnFkl8seSRAMJb8YskvJEAYS36x5JckQERERERERCRA7FG4HoXrI0ADnTbQaQMkQEGnDXTawCNA7+7u7u7uI0C4HoXrUbgjQClcj8L1qCNA84slv1hyI0A=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_min\":{\"__ndarray__\":\"AAAAAAAAKEAAAAAAAAAmQAAAAAAAACZAZmZmZmZmJkCamZmZmZklQJqZmZmZmSVAmpmZmZmZJUAzMzMzMzMlQJqZmZmZmSVAmpmZmZmZJECamZmZmZkkQJqZmZmZmSRAzczMzMzMJEAAAAAAAAAlQGZmZmZmZiRAAAAAAAAAJEBmZmZmZuYjQEjhehSuRyRAH4XrUbgeJEAAAAAAAIAkQHsUrkfh+iNA16NwPQrXI0DsUbgehesjQK5H4XoUriNAPQrXo3C9I0AzMzMzM7MjQOF6FK5HYSNAw/UoXI9CI0A=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Time_std\":{\"__ndarray__\":\"MjMzMzMz0z+AmZmZmZm5PxC45ghyj70/pLjmCHKPrT8QuOYIco+9PxC45ghyj60/ELjmCHKPrT+dILAJZY3DPxC45ghyj60/ELjmCHKPrT+AmZmZmZm5PxC45ghyj60/AAAAAAAAAAAQuOYIco+tP6S45ghyj60/ELjmCHKPvT/ciVWbcfmvP7L4aTHLVLg/1FuOZ/ZQpT/RTW45NrG0P6MWP5UXAcA/K04+QN51oj9EW45n9lClPyJ8NxRgdaA/zW20vM9dtj8AFK5H4XqEP/tCvWrMJL8/jFuOZ/ZQtT8=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[28]},\"Year\":[\"1896\",\"1900\",\"1904\",\"1906\",\"1908\",\"1912\",\"1920\",\"1924\",\"1928\",\"1932\",\"1936\",\"1948\",\"1952\",\"1956\",\"1960\",\"1964\",\"1968\",\"1972\",\"1976\",\"1980\",\"1984\",\"1988\",\"1992\",\"1996\",\"2000\",\"2004\",\"2008\",\"2012\"]},\"selected\":{\"id\":\"4748\"},\"selection_policy\":{\"id\":\"4747\"}},\"id\":\"4519\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"height\":{\"value\":0.4},\"left\":{\"field\":\"Time_min\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"Time_max\"},\"y\":{\"field\":\"Year\"}},\"id\":\"4554\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"4743\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"4538\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"4532\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"4745\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"4535\"},\"coordinates\":null,\"dimension\":1,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"4537\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"height\":{\"value\":0.4},\"left\":{\"field\":\"Time_min\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"right\":{\"field\":\"Time_max\"},\"y\":{\"field\":\"Year\"}},\"id\":\"4555\",\"type\":\"HBar\"},{\"attributes\":{\"overlay\":{\"id\":\"4544\"}},\"id\":\"4540\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"4539\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"4748\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"4541\",\"type\":\"SaveTool\"}],\"root_ids\":[\"4520\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"b0af28e7-f787-4a33-b9da-0c0463d50ee7\",\"root_ids\":[\"4520\"],\"roots\":{\"4520\":\"315ca884-0e14-4722-a15d-3137473c9752\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "4520"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "from bokeh.sampledata.sprint import sprint\n",
    "sprint.Year = sprint.Year.astype(str)\n",
    "group = sprint.groupby('Year')\n",
    "source = ColumnDataSource(group)\n",
    "# 画布\n",
    "p = figure(y_range=group, x_range=(9.5,12.7), plot_width=400, plot_height=550, \n",
    "#            toolbar_location=None,\n",
    "           title=\"Time Spreads for Sprint Medalists (by Year)\")\n",
    "# 绘图\n",
    "p.hbar(y=\"Year\", left='Time_min', right='Time_max', height=0.4, source=source) # 水平柱状图\n",
    "# 其他\n",
    "p.ygrid.grid_line_color = None\n",
    "p.xaxis.axis_label = \"Time (seconds)\"\n",
    "p.outline_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
